<!-- lin -->
<template>
	<view>
		<view class="header">
			<navigator url="" class="city">
				<text class="citytext">{{city}}</text>
				<image class="cityIcon" src="../../static/icons/lx/icon_nav_select2x.png" mode=""></image>
			</navigator>
			<view class="search">
				<image class="searchImg" src="../../static/icons/lx/icon_navSearch2x.png" mode=""></image>
				<input class="searchInput" v-model="keyword" type="text" @blur="jumpSearch" value=""
					placeholder="滤清器" />
				<image class="photo" @tap.stop="camera" src="../../static/icons/lx/icon_navScan2x.png" mode=""></image>
			</view>
			<view class="bell">
				<image class="bellImg" @tap="jumpMsgPage" src="../../static/icons/lx/icon_nav_message2x.png" mode="">
				</image>
			</view>
		</view>
		<view class="chooseCar">
			<view class="chooseCarWrap">
				<image class="carIcon" src="../../static/icons/lx/Image_aodi2x.png" mode=""></image>
				<navigator class="carText" url="../vehicle/vehicle">大众奥迪 A6L新能源</navigator>
				<view class="switchCar">
					<!-- <navigator class="switchCarNavg" url="../selector/index"> -->
					<text class="switchCarText">更换汽车</text>
					<image class="switchCarIcon" src="../../static/icons/lx/arrow2x.png" mode=""></image>
					<!-- </navigator> -->
				</view>
			</view>
		</view>
		<view class="nav">
			<navigator class="navItem" url="../classification/classification">
				<image class="navItemIcon" src="../../static/icons/lx/icon_baoyang2x.png" mode=""></image>
				<text class="navItemText">做保养</text>
			</navigator>
			<navigator class="navItem" url="../beauty/beauty">
				<image class="navItemIcon" src="../../static/icons/lx/icon_meirong2x.png" mode=""></image>
				<text class="navItemText">做美容</text>
			</navigator>
			<navigator class="navItem" url="">
				<image class="navItemIcon" src="../../static/icons/lx/icon_luntai2x.png" mode=""></image>
				<text class="navItemText">换轮胎</text>
			</navigator>
			<navigator class="navItem lastItem" url="">
				<image class="navItemIcon" src="../../static/icons/lx/icon_huiyuan2x.png" mode=""></image>
				<text class="navItemText">会员服务</text>
			</navigator>
			<navigator class="navItem" url="">
				<image class="navItemIcon" src="../../static/icons/lx/icon_jiayou2x.png" mode=""></image>
				<text class="navItemText">加油</text>
			</navigator>
			<navigator class="navItem" url="">
				<image class="navItemIcon" src="../../static/icons/lx/icon_jiuyuan2x.png" mode=""></image>
				<text class="navItemText">救援</text>
			</navigator>
			<navigator class="navItem" url="">
				<image class="navItemIcon" src="../../static/icons/lx/icon_weizhang2x.png" mode=""></image>
				<text class="navItemText">查违章</text>
			</navigator>
			<navigator class="navItem lastItem" url="">
				<image class="navItemIcon" src="../../static/icons/lx/icon_daijia2x.png" mode=""></image>
				<text class="navItemText">代驾</text>
			</navigator>

		</view>
		<!-- 秒杀 -->
		<view class="sec_kill_floor">
			<view class="title_wrap">
				<navigator class="seckill_left_link" url="../secondkill/secondkill">
					<view class="seckill_tit_img">
						蜗牛秒杀
					</view>
					<view class="seckill_time">
						<view class="seckill_time_h seckill_time_i">{{hour}}</view>
						<text class="seckill_sperator">:</text>
						<view class="seckill_time_m seckill_time_i">{{minute}}</view>
						<text class="seckill_sperator">:</text>
						<view class="seckill_time_s seckill_time_i">{{second}}</view>
					</view>
				</navigator>
				<navigator class="seckill_more_link" url="../secondkill/secondkill">
					<view class="seckill_more_text">
						更多秒杀
					</view>
					<image class="seckill_more_img"
						src="https://wq.360buyimg.com/wxsq_project/portal/m_jd_index/images/arrow_rt_2ccb8cd5.png"
						mode=""></image>
				</navigator>
			</view>
			<view class="seckill_container">
				<scroll-view scroll-x="true">
					<view class="seckill_contain">
						<navigator class="seckill-item" url="../secondkill/secondkill" v-for="item in seckillData"
							:key="item.id">
							<view class="seckill_item_img">
								<image class="seckill_photo" :src="item.photo" mode=""></image>
							</view>
							<view class="seckill_price_wrap">
								<view class="seckill_new_price">
									￥{{item.newPrice}}
								</view>
								<view class="seckill_old_price">
									￥{{item.price}}
								</view>
							</view>
						</navigator>
					</view>
				</scroll-view>
			</view>
		</view>
		<!-- 汽车推荐区是动态的 -->
		<view class="carRecommend">
			<template v-for="(car, index) in floordata">
				<view class="bigImg" v-if="index==0" :key="car.name">
					<view class="bigTextDiv">
						<image class="bigTextImg" src="../../static/icons/lx/icon_yinhao2x.png" mode=""></image>
						<text class="bigText">{{car.name}}</text>
					</view>
					<text class="bigInfo">{{car.introduce}}</text>
					<view class="toIcon">
						<text class="toText">GO</text>
					</view>
					<image class="imgBig" src="../../static/images/lx/defaultCar.jpg" mode=""></image>
				</view>
				<view class="smallImg" v-else-if="index==1" :key="car.name">
					<text class="smallText">{{car.name}}</text>
					<text class="smallInfo">{{car.introduce}}</text>
					<view class="toIconSDiv">
						<view class="toIconS">
							<text class="toText">详情</text>
							<image class="toImg" src="../../static/icons/lx/arrow2x.png" mode=""></image>
						</view>
						<image class="imgSmall" src="../../static/images/lx/defaultCar.jpg" mode=""></image>
					</view>
				</view>
				<view class="smallImgTwo" v-else :key="car.name">
					<text class="smallText">{{car.name}}</text>
					<text class="smallInfo">{{car.introduce}}</text>
					<view class="toIconSDiv">
						<view class="toIconS">
							<text class="toText">详情</text>
							<image class="toImg" src="../../static/icons/lx/arrow2x.png" mode=""></image>
						</view>
						<image class="imgSmall" src="../../static/images/lx/defaultCar.jpg" mode=""></image>
					</view>
				</view>
			</template>
		</view>
		<view class="bar">
			<view class="barItem">
				<image class="barImg" src="../../static/icons/lx/icon_r_fugai2x.png" mode=""></image>
				<text class="barText">城市覆盖</text>
			</view>
			<view class="barItem">
				<image class="barImg" src="../../static/icons/lx/icon_r_baoyang2x.png" mode=""></image>
				<text class="barText">就近保养</text>
			</view>
			<view class="barItem">
				<image class="barImg" src="../../static/icons/lx/icon_r_zhiying2x.png" mode=""></image>
				<text class="barText">正品直营</text>
			</view>
			<view class="barItem">
				<image class="barImg" src="../../static/icons/lx/icon_r_shouhou2x.png" mode=""></image>
				<text class="barText">售后保障</text>
			</view>

		</view>
		<!-- 滑块 -->
		<view class="swiperDiv">
			<swiper class="swiper" indicator-dots="true" indicator-color="#ccc" duration="500"
				indicator-active-color="#ff5500" previous-margin="130rpx" next-margin="130rpx" circular="true">
				<swiper-item class="swiper_item" v-for="item in swiperData" :key="item.img_id">
					<image class="swiper-img" :src="item.img_src" mode=""></image>
				</swiper-item>
			</swiper>
		</view>
		<view class="titleTui">
			<image class="titleTuiImg" src="../../static/images/lx/home-title.png" mode=""></image>
		</view>
		<!-- 商品区 -->
		<view class="goodsArea">
			<!-- 有个商品goodsId，唯一id -->
			<view class="goodItem" v-for="good in goodsData" :key="good.goodsId" @tap="jumpGoodDetail(good)">
				<image class="goodImg" :src="good.goodsImg"></image>
				<view class="goodInfoDiv">
					<text class="goodInfoText">{{good.goodsName}}</text>
				</view>
				<view class="goodPriceDiv">
					<text class="goodPrice">￥{{good.goodsPrice}}</text>
					<text class="goodOldPrice">￥{{good.goodsPrice+100}}</text>
					<text class="findSame">找相似</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		createNamespacedHelpers
	} from 'vuex';
	let {
		mapActions,
		mapState
	} = createNamespacedHelpers('goods')
	export default {
		components: {

		},
		data() {
			return {
				keyword: '',
				city: '成都市',
				floordata: [{
						"name": "家用SUV保养",
						"introduce": "小型家用SUV的正确保养方式，速速get",
						"image_src": "../../static/images/lx/defaultCar.jpg"
					},
					{
						"name": "家用SUV保养2",
						"introduce": "小型家用SUV",
						"image_src": "../../static/images/lx/defaultCar.jpg"
					},
					{
						"name": "家用SUV保养3",
						"introduce": "小型家用SUV",
						"image_src": "../../static/images/lx/defaultCar.jpg"
					}
				],
				swiperData: [{
						img_id: 1,
						img_src: '../../static/images/lx/swiper_byd.jpg'
					},
					{
						img_id: 2,
						img_src: '../../static/images/lx/swiper_byd.jpg'
					},
					{
						img_id: 3,
						img_src: '../../static/images/lx/swiper_byd.jpg'
					}
				],

				goodsData: [

				],

				seckillEndTime: "2021-05-10T22:00:00",
				hour: '',
				minute: '',
				second: ''
			}
		},
		onLoad() {
			// 发请求去获取路径
			// uni.request({
			// 	url: 'http://pub.woniulab.com:8081/pub/site/xiancar', 
			// 	success: (res) => {
			// 		console.log(res.data)
			// 		this.text = 'request success';
			// 		let serveURL = res.data.data.protocol + "://" + res.data.data.baseUrl + ":" + res.data.data
			// 			.port;
			// 		console.log(serveURL);
			// 		uni.setStorageSync('serveURL', serveURL);
			// 	}
			// });

			// if (uni.getStorageSync("serveURL")) {
				this.Time();
				this.getRecommend();
				this.seckillGoods();
			// }
		},
		onUnload() {
			this.keyword = "";
		},
		methods: {
			...mapActions(['homeGoods', 'seckillGoods']),
			// 打开摄像机
			camera() {
				// 自定义扫码
				// uni.navigateTo({
				// 	url: '../homeScan/homeScan'
				// })
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
					}
				});
			},
			jumpMsgPage() {
				uni.navigateTo({
					url: '../messageAll/messageAll'
				})
			},
			jumpSearch() {
				if (this.keyword) {
					uni.navigateTo({
						url: '../profqTwo/profqTwo?keyword=' + this.keyword
					})
				}
			},
			// 秒杀获取时间
			Time() {
				var T = new Date(this.seckillEndTime);
				var time = T.getTime() / 1000;
				setInterval(() => {
					var date = new Date();
					var totalS = time - date.getTime() / 1000;
					this.hour = parseInt(totalS / 3600);
					this.minute = parseInt((totalS - this.hour * 3600) / 60);
					this.second = Math.floor(totalS % 60);
					if (this.hour < 10) {
						this.hour = '0' + this.hour;
					}
					if (this.minute < 10) {
						this.minute = '0' + this.minute;
					}
					if (this.second < 10) {
						this.second = '0' + this.second;
					}
				}, 1000)
			},
			// 交互底部商品推荐
			async getRecommend() {
				const goods = await this.homeGoods();
				// 返回数据第一个为空，截取
				let arr = goods.list;
				arr.splice(0, 1)
				this.goodsData = arr;
			},
			// 点击商品跳转商品详情
			jumpGoodDetail(good) {
				uni.navigateTo({
					url: '../xqfq/xqfq?id=' + good.goodsId
				})
			}
		},
		computed: {
			...mapState(['seckillData']),
		}
	}
</script>

<style>
	page {
		background-color: #f5f5f5;
	}

	.header {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		padding-right: 30rpx;
		background-color: #fff;
	}

	.city {
		display: flex;
		justify-content: center;
		align-items: center;
		margin-left: 30rpx;
		color: rgb(102, 102, 102);
	}

	.cityIcon {
		width: 15rpx;
		height: 9rpx;
		vertical-align: middle;
	}

	.citytext {
		vertical-align: middle;
		font-family: PingFang SC;
		font-size: 14px;
		color: #666666;
	}

	.search {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		margin-left: 24rpx;
		width: 488rpx;
		height: 56rpx;
		border: solid 2rpx #f5610c;
		border-radius: 28rpx;
	}

	.searchImg {
		margin-left: 10rpx;
		width: 36rpx;
		height: 32rpx;
	}

	.searchInput {
		width: 350rpx;
	}

	.photo {
		margin-left: 40rpx;
		width: 40rpx;
		height: 40rpx;
	}

	.bell {
		width: 60rpx;
		height: 60rpx;
	}

	.bellImg {
		margin-left: 10rpx;
		width: 60rpx;
		height: 60rpx;
	}

	/* header end */

	/* chooseCar start*/
	.chooseCar {
		display: flex;
		align-items: center;
		width: 100%;
		height: 88rpx;
		background-color: #FFFFFF;
	}

	.chooseCarWrap {
		display: flex;
		align-items: center;
		justify-content: flex-start;
		width: 100%;
		height: 60rpx;
	}

	.carIcon {
		margin-left: 60rpx;
		width: 88rpx;
		height: 88rpx;
	}

	.carText {
		width: 220rpx;
		height: 34rpx;
		font-family: PingFang SC;
		font-size: 24rpx;
		line-height: 34rpx;
		color: #000000;
	}

	.switchCarText {
		margin-left: 8rpx;
		width: 80rpx;
		height: 60rpx;
		font-family: PingFang SC;
		font-size: 20rpx;
		line-height: 60rpx;
		letter-spacing: 0rpx;
		color: #9a9a9a;
	}

	.switchCar {
		display: flex;
		align-items: center;
		margin-left: 216rpx;
	}

	.switchCarNavg {
		display: flex;
		align-items: center;
	}

	.switchCarIcon {

		width: 40rpx;
		height: 40rpx;
	}

	/* 导航区 */
	.nav {
		box-sizing: border-box;
		display: flex;
		flex-wrap: wrap;
		margin: 0 auto;
		padding-left: 46rpx;
		padding-top: 42rpx;
		width: 690rpx;
		height: 372rpx;
		background-color: #fff;
		border-radius: 20rpx;
	}

	.navItem {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		margin-right: 68rpx;
		margin-bottom: 32rpx;
		width: 96rpx;
		height: 130rpx;
	}

	.lastItem {
		margin-right: 0;
	}

	.navItemIcon {
		width: 96rpx;
		height: 96rpx;
	}

	.navItemText {
		width: 96rpx;
		height: 34rpx;
		font-family: PingFang SC;
		font-size: 24rpx;
		line-height: 34rpx;
		color: #515151;
		text-align: center;
	}

	/* 秒杀 */
	.sec_kill_floor {
		box-sizing: border-box;
		padding: 0 20rpx;
		width: 680rpx;
		margin: 20rpx auto;
		background-color: #fff;
		border-radius: 20rpx;
	}

	.title_wrap {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.seckill_left_link {
		display: flex;
		justify-content: space-between;
		align-items: center;
		/* width: 360rpx; */
		width: 255rpx;
		height: 70rpx;
	}

	.seckill_tit_img {
		font-size: 28rpx;
		color: #333;
	}

	.seckill_time {
		display: flex;
		align-items: center;
		justify-content: flex-start;
		font-size: 24rpx;
	}

	.seckill_time_i {
		width: 30rpx;
		color: #fff;
		background-color: #fa2c19;
		border-radius: 4rpx;
		text-align: center;
	}

	.seckill_sperator {
		padding: 0 5rpx;
	}

	.seckill_more_link {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 130rpx;
		height: 66rpx;
	}

	.seckill_more_text {
		vertical-align: middle;
		font-size: 24rpx;
		color: #f23030;
	}

	.seckill_more_img {
		vertical-align: middle;
		width: 22rpx;
		height: 22rpx;
	}

	.seckill_contain {
		display: flex;
		align-items: center;
		justify-content: flex-start;
	}

	.seckill-item {
		margin-top: 20rpx;
		margin-right: 10rpx;
		width: 114rpx;
		height: 206rpx;
	}

	.seckill_item_img {
		margin-bottom: 10rpx;
		width: 110rpx;
		height: 110rpx;
		background-color: skyblue;
	}

	.seckill_photo {
		width: 110rpx;
		height: 110rpx;
	}

	.seckill_new_price {
		font-size: 26rpx;
		color: #f2270c;
		text-align: center;
	}

	.seckill_old_price {
		font-size: 24rpx;
		color: #999;
		text-align: center;
	}

	/* 汽车推荐区 */
	.carRecommend {
		overflow: hidden;
		margin: 20rpx auto;
		width: 690rpx;
		height: 380rpx;
		border-radius: 12rpx;
	}

	.bigImg {
		box-sizing: border-box;
		padding: 16rpx 0 0 24rpx;
		float: left;
		width: 334rpx;
		height: 380rpx;
		margin-right: 10rpx;
		background-color: #ffffff;
		box-shadow: 0rpx 6rpx 12rpx 0rpx #ededed;
	}

	.smallImg {
		float: left;
		box-sizing: border-box;
		padding: 16rpx 0 0 24rpx;
		margin-bottom: 10rpx;
		width: 344rpx;
		height: 184rpx;
		background-color: #ffffff;
		box-shadow: 0rpx 6rpx 12rpx 0rpx rgba(237, 237, 237, 0.16);
	}

	.smallImgTwo {
		float: left;
		box-sizing: border-box;
		padding: 16rpx 0 0 24rpx;
		width: 344rpx;
		height: 184rpx;
		background-color: #ffffff;
		box-shadow: 0rpx 6rpx 12rpx 0rpx rgba(237, 237, 237, 0.16);
	}

	.bigTextDiv {
		display: flex;
		justify-content: flex-start;
		align-items: center;
	}

	.bigTextImg {
		width: 60rpx;
		height: 60rpx;
	}

	.bigText {
		margin-left: 12rpx;
		font-size: 32rpx;
		line-height: 44rpx;
		color: #3f3f3f;
		text-align: center;
	}

	.bigInfo {
		display: block;
		width: 288rpx;
		height: 68rpx;
		font-family: PingFang SC;
		font-size: 24rpx;
		line-height: 34rpx;
		color: #777777;
	}

	.toIcon {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 64rpx;
		height: 34rpx;
		background-color: #ee1515;
		border-radius: 18rpx;
		text-align: center;
	}

	.imgBig {
		width: 302rpx;
		height: 176rpx;
	}

	.imgSmall {
		width: 220rpx;
		height: 100rpx;
	}

	.smallText {
		width: 344rpx;
		height: 40rpx;
		font-family: PingFang SC;
		font-size: 28rpx;
		line-height: 40rpx;
		color: #3f3f3f;
		text-align: center;
	}

	.smallInfo {
		display: block;
		height: 28rpx;
		font-family: PingFang SC;
		font-size: 20rpx;
		line-height: 28rpx;
		color: #777777;
	}

	/* go */
	.toIconSDiv {
		display: flex;
		align-items: flex-start;
		justify-content: space-between;
	}

	.toIconS {
		display: flex;
		align-items: center;
		justify-content: center;
		vertical-align: top;
		height: 32rpx;
		width: 88rpx;
		background-color: #ee1515;
		border-radius: 18rpx;
		text-align: center;
	}

	.toText {
		font-family: PingFang SC;
		font-size: 20rpx;
		color: #ffffff;
	}

	.toImg {
		width: 15rpx;
		height: 25rpx;
	}

	/* bar */
	.bar {
		margin: 0 auto;
		box-sizing: border-box;
		padding-left: 34rpx;
		margin-top: 20rpx;
		width: 690rpx;
		height: 60rpx;
		background-color: #ffffff;
		box-shadow: 0rpx 6rpx 12rpx 0rpx rgba(237, 237, 237, 0.16);
		border-radius: 30rpx;
	}

	.barItem {
		display: inline-block;
		margin-right: 38rpx;
	}

	.barImg {
		width: 44rpx;
		height: 44rpx;
		vertical-align: middle;
	}

	.barText {
		width: 80rpx;
		height: 28rpx;
		font-family: PingFang SC;
		font-size: 20rpx;
		line-height: 28rpx;
		color: #444444;
		vertical-align: middle;
	}

	/* 滑块区 start */
	.swiperDiv {
		margin-top: 20rpx;
		width: 100%;
		overflow: hidden;
	}

	.swiper_item {
		border-radius: 20rpx;
		overflow: hidden;
	}

	.swiper-img {
		margin: 0 16rpx;
		width: 470rpx;
		height: 220rpx;
		border-radius: 20rpx;

	}

	/* title */
	.titleTui {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.titleTuiImg {
		width: 435rpx;
		height: 45rpx;
	}

	/* 商品区 */
	.goodsArea {
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;
		margin: 30rpx auto;
		width: 690rpx;
	}

	.goodItem {
		overflow: hidden;
		margin-bottom: 20rpx;
		margin-right: 10rpx;
		width: 333rpx;
		/* height: 442rpx; */
		background-color: #ffffff;
		border-radius: 20rpx;
	}

	.goodImg {
		width: 333rpx;
		height: 284rpx;
	}

	.goodInfoDiv {
		height: 152rpx;
		overflow: hidden;
		box-sizing: border-box;
		padding-left: 20rpx;
	}

	.goodInfoText {
		width: 286rpx;
		height: 70rpx;
		font-family: PingFang SC;
		font-size: 24rpx;
		line-height: 34rpx;
		color: #3a3a3a;
	}

	.goodPriceDiv {
		width: 286rpx;
		display: flex;
		justify-content: space-between;
	}

	.goodPrice {
		width: 126rpx;
		height: 44rpx;
		font-family: DIN;
		font-size: 20rpx;
		font-weight: normal;
		font-stretch: normal;
		line-height: 44rpx;
		letter-spacing: 0rpx;
		color: #ff0000;
	}

	.goodOldPrice {
		width: 54rpx;
		height: 26rpx;
		font-family: PingFang SC;
		font-size: 18rpx;
		font-weight: normal;
		font-stretch: normal;
		line-height: 40rpx;
		letter-spacing: 0rpx;
		color: #b8b8b8;
	}

	.findSame {
		width: 54rpx;
		height: 26rpx;
		font-family: PingFang SC;
		font-size: 18rpx;
		font-weight: normal;
		font-stretch: normal;
		line-height: 40rpx;
		letter-spacing: 0rpx;
		color: #b8b8b8;
	}
</style>
